<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <div class="row h-home-path">
          <div class="col-md-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">编辑枚举对象信息</li>
            </ol>
          </div>
        </div>
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" id="return-btn" onclick="returnIndex()"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>返回
              </button>
              <@permission btnType="save" btnId="saveBtn" btnValue="保存" op="api:facadeObjEnum:save"
              btnMethod="ApiFacadeObjEnumMgr.submitForm()"/>
            </div>
          </form>
        </div>

        <div class="form-horizontal  h-form-warp">
          <div class="h-msg-title h-table-header">
            <strong>枚举对象信息</strong>
          </div>
          <form action="/apiFacadeObjEnum/saveApiFacadeObjEnum" class="form-horizontal" id="apiFacadeObjEnumForm"
                method="post" role="form">
            <input id="operation" name="operation" type="hidden" value="${operation!}"/>
            <input class="form-control" id="id" name="id" type="hidden" value="${apiFacadeObjEnum.id!}">
            <input class="form-control" id="parentId" name="parentId" type="hidden"
                   value="${apiFacadeObjEnum.parentId!}">
            <div class="form-group">
              <label class="col-sm-2 control-label">枚举编码 ：</label>
              <div class="col-sm-8">
                <input class="form-control" id="enumCode" name="enumCode" required="required"
                       type="text"
                       value="${apiFacadeObjEnum.enumCode!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">枚举名称 ：</label>
              <div class="col-sm-8">
                <input class="form-control" id="enumName" name="enumName" required="required"
                       type="text"
                       value="${apiFacadeObjEnum.enumName!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">枚举包路径 ：</label>
              <div class="col-sm-8">
                <input class="form-control" id="enumPackage" name="enumPackage" required="required"
                       type="text"
                       value="${apiFacadeObjEnum.enumPackage!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">说明 ：</label>
              <div class="col-sm-8">
                <input class="form-control" id="enumComment" name="enumComment" required="required"
                       type="text"
                       value="${apiFacadeObjEnum.enumComment!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group" id="enumItemDiv">
              <label class="col-sm-2 control-label"></label>
              <button class="btn btn-info col-sm-2" id="addEnumItem" onclick="ApiFacadeObjEnumMgr.addEnumItem()"
                      type="button"><i class="fa fa-plus">&nbsp;&nbsp;</i>新增枚举字段信息
              </button>
            </div>
            <div class="h-msg-title h-table-header">
              <strong>枚举字段信息</strong>
            </div>
            <div class="form-group" style="width:800px;margin-left:180px">
              <table class="table-bordered table-hover text-center dataTable no-footer">
                <thead>
                <tr role="row">
                  <td>code</td>
                  <td>value</td>
                  <td>desc</td>
                  <td>操作</td>
                </tr>
                </thead>
                <tbody>
                <#list itemEnumList as item>
                <tr>
                  <td class="text-left">${item.enumItemCode!}</td>
                  <td class="text-left">${item.enumItemKey!}</td>
                  <td class="text-left">${item.enumItemDesc!}</td>
                  <td>
                    <#if operation !='view'>
                    <a href="javascript:void(0);" onclick="ApiFacadeObjEnumMgr.updateItem('${item.id!}')">修改</a>
                    <a href="javascript:void(0);" onclick="ApiFacadeObjEnumMgr.deleteItem('${item.id!}')">删除</a>
                  </#if>
                  </td>
                </tr>
                </#list>
                </tbody>
              </table>
            </div>
          </form>
        </div>
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
</div>

<#include "/common/jslib.html">
<!-- 弹窗下拉 -->
<script type="text/javascript">
    function returnIndex() {
        window.location.href = "/apiFacadeObjEnum/query";
    }

    $(function () {
        // 页面操作类型：add(添加)-edit(编辑)-view(查看)
        var operation = $("#operation").val();
        // 弹出窗体控制
        ApiFacadeObjEnumMgr = {
            // 初始化
            init: function () {
                // 查看的时候不显示保存按钮
                if (operation == "view") {
                    Jmts.setFormReadOnly();
                    $("#saveBtn").hide();
                    $("#enumItemDiv").hide();
                } else if (operation == 'add') {
                    $("#enumItemDiv").hide();
                }

            },
            // init end

            // 提交数据
            submitForm: function () {
                //提交前校验当前枚举是否已存在
                Jmts.ajaxSubmit(document.getElementById("apiFacadeObjEnumForm"), function (result) {
                    if (result.success) {
                        if (operation == 'add') {
                            window.location.href = "/apiFacadeObjEnum/to-form?operation=edit&id=" +
                                result.resultData.id;
                        } else {
                            Jmts.succTips(result.msg);
                            window.location.reload();
                        }
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            },
            // submitForm end
            returnIndex: function () {
                window.location.href = "/apiFacadeObjEnum/query";
            },
            //新增枚举信息子项
            addEnumItem: function () {
                var parentId = $("#id").val();
                var url = "/apiFacadeObjEnum/to-itemForm?parentId=" + parentId + "&operation=add";
                Jmts.openDialog("dictItem", url, "新增枚举信息子项", 300, 500, 32);
            },
            updateItem: function (id) {
                var url = "/apiFacadeObjEnum/to-itemForm?id=" + id + "&operation=edit";
                Jmts.openDialog("dictItem", url, "修改枚举信息子项", 300, 500, 32);
            },
            viewItem: function () {
                var url = "/apiFacadeObjEnum/to-itemForm?id=" + id + "&operation=view";
                Jmts.openDialog("dictItem", url, "查看枚举信息子项", 300, 500, 32);
            },
            deleteItem: function (id) {
                var data = {
                    "id": id
                };
                var url = "/apiFacadeObjEnum/delete";
                Jmts.deleteItem("确定要删除吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("删除成功");
                        window.location.reload();
                    }
                });
            }
        };
        // 执行初始化
        ApiFacadeObjEnumMgr.init();
        // 前台验证表单
        $("#apiFacadeObjEnumForm").validate();
    });
</script>
</body>
</html>
